package Thread;

/*通过实现java.lang.Runnable接口的方式创建一个新线程，
要求main线程打印100次”main”，新线程打印50次“new”。*/
public class Test2 implements Runnable {
    public void run() {
        for (int i = 0; i < 50; i++) {
            System.out.println(Thread.currentThread().getName()+":" + "new"+i+"次");
        }
    }

    public static void main(String[] args) {
        Runnable rb=new Test2();
        Thread td=new Thread(rb,"新线程");
        Thread.currentThread().setName("主线程");
        td.start();
        for(int i=0;i<100;i++){
            System.out.println(Thread.currentThread().getName()+":"+"main"+i+"次");
        }
    }
}
